#ifndef __CHOICE_VIEW_H__
#define __CHOICE_VIEW_H__

#include <list>
#include <vector>
#include "gofgame/common/Ref.h"
#include "gofgame/common/ui/Container.h"
#include "gofgame/common/ui/Template.h"
#include "gofgame/common/graphics/Brush.h"

namespace gofgame {
	namespace common {
		namespace ui {

			using namespace gofgame::common;
			using namespace gofgame::common::ui;
			using namespace gofgame::common::graphics;

			class ChoiceView : public Container {
			public:
				ChoiceView();
				virtual bool init() _override;

				virtual float getMiddleSpacing() const;
				virtual void setMiddleSpacing(float middleSpacing);
				virtual const CCSize &getItemSize() const;
				virtual void setItemSize(const CCSize &itemSize);
				virtual float getItemSpacing() const;
				virtual void setItemSpacing(float itemSpacing);
				virtual float getItemPadding() const;
				virtual void setItemPadding(float itemPadding);
				virtual bool isAutoHeightUsed() const;
				virtual void setAutoHeightUsed(bool autoHeightUsed);

				virtual Brush *getSourceItemBackgroundBrush() const;
				virtual void setSourceItemBackgroundBrush(Brush *sourceItemBackgroundBrush);
				virtual Brush *getSourceSelectedItemBackgroundBrush() const;
				virtual void setSourceSelectedItemBackgroundBrush(Brush *sourceSelectedItemBackgroundBrush);
				virtual Brush *getTargetItemBackgroundBrush() const;
				virtual void setTargetItemBackgroundBrush(Brush *targetItemBackgroundBrush);

				virtual Template *getSourceItemTemplate() const;
				virtual void setSourceItemTemplate(Template *sourceItemTemplate);
				virtual Template *getSourceSelectedItemTemplate() const;
				virtual void setSourceSelectedItemTemplate(Template *sourceSelectedItemTemplate);
				virtual Template *getTargetItemTemplate() const;
				virtual void setTargetItemTemplate(Template *targetItemTemplate);

				virtual void setDataSource(const list<Ref<CCObject>> &dataSource);
				virtual void setDataSource(const vector<Ref<CCObject>> &dataSource);

				disable_children_management();

			private:
				void addChoiceItem(CCObject *dataItem);
				void item_click(void *sender, ComponentEventArgs &e);
				void selectedItem_click(void *sender, ComponentEventArgs &e);
				void changeItem(CCObject *dataItem, bool selected);

			private:
				Ref<Template> sourceItemTemplate;
				Ref<Template> sourceSelectedItemTemplate;
				Ref<Template> targetItemTemplate;
				Ref<Container> allItemContainer;
				Ref<Container> selectedItemContainer;
				Ref<Brush> sourceItemBackgroundBrush;
				Ref<Brush> sourceSelectedItemBackgroundBrush;
				Ref<Brush> targetItemBackgroundBrush;
				float middleSpacing;
				bool autoHeightUsed;
				static const Key USK_SELECTED;
				static const Key URK_DATA_ITEM;
			};
		}
	}
}

#endif //__CHOICE_VIEW_H__
